package com.ljc.websocket.chat.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import javax.websocket.Session;

@Controller
@RequestMapping("chat")
public class ChatController {

    /**
     * 跳转至聊天室页面
     * @param userName
     //* @param model
     * @return
     */
    @RequestMapping("/chatRoom")
    public String webSocket(String userName, HttpSession session){
        session.setAttribute("userName",userName);
        return "chatRoom";
    }

    /**
     * 获取用户名称
     * @param session
     * @return
     */
    @RequestMapping("getUserName")
    @ResponseBody
    public String getUserName(HttpSession session){

        return session.getAttribute("userName").toString();
    }

}
